<template>
  <el-dialog :title="title" :visible.sync="dialogVisible" :before-close="handleClose">
    <el-form :model="formInline" class="form" label-position="right" label-width="140px" size="small" :rules="rules" ref="formInline">
      <div style="display:flex">
        <div class="box_left">
          <el-form-item label="单位名称">
            <el-input v-model="formInline.orgName" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="组织机构代码">
            <el-input v-model="formInline.orgOrganizationCode" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="法人代表：">
            <el-input v-model="formInline.orgLegalPerson" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="座机号：">
            <el-input v-model="formInline.orgLandline" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="地址：">
            <el-input v-model="formInline.orgAddr" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="行政区代码：">
            <el-input v-model="formInline.orgAreaCode" :disabled="disable"></el-input>
          </el-form-item>
        </div>
        <div class="box_right">
          <el-form-item label="上级单位" label-width="100px" prop="pid">
            <el-select v-model="formInline.pid" placeholder="请选择" size='small' filterable  clearable allow-create :disabled="disable">
              <el-option v-for="item in manageOrgList" :key="item.id" :label="item.orgName" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="营业执照登记机构：">
            <el-input v-model="formInline.orgBlrOrg" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="成立日期：">
            <el-input v-model="formInline.orgEstablishDate" :disabled="disable"></el-input>
          </el-form-item>

          <el-form-item label="传真：">
            <el-input v-model="formInline.orgFax" :disabled="disable"></el-input>
          </el-form-item>
          <el-form-item label="手机号：">
            <el-input v-model="formInline.orgTel" :disabled="disable"></el-input>
          </el-form-item>
        </div>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="success" @click="getEdit('formInline')" size='small' v-if="title=='单位修改'">修改保存</el-button>
      <el-button type="success" @click="getAdd('formInline')" size='small' v-if="title=='单位添加'">新增保存</el-button>
      <el-button size='small' @click="handleClose" v-if="title!='单位详情'">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getAdminmanageOrgInfo,editAdminmanageOrgInfo, addAdminmanageOrgInfo,getadminOrgInfoList } from '@/api/manageOrgManage'
export default {
  data () {
    return {
      certFileName: null,
      loading: false,
      fileList1: [],
      manageOrgList:[],
      disable: false,
      title: '',
      dialogVisible: false,
      formInline: {
      },
      fileList: [],
      rules: {}
    }
  },
  mounted () {
  },
  methods: {
    handleClick () {
      this.fileList1 = [],
        this.formInline.certFilepath = ''
      this.certFileName = null
    },
    getEdit (formInline) {
      this.$refs[formInline].validate((valid) => {
        if (valid) {
          editAdminmanageOrgInfo(this.formInline).then(res => {
            if (res.data.code == '200') {
              this.handleClose()
              this.$parent.gettableData()
            } else {
              this.$message({
                type: 'warning',
                message: res.data.msg
              })
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })

    },
    getAdd (formInline) {
      this.$refs[formInline].validate((valid) => {
        if (valid) {
          addAdminmanageOrgInfo(this.formInline).then(res => {
            if (res.data.code == '200') {
              this.handleClose()
              this.$parent.gettableData()
            } else {
              this.$message({
                type: 'warning',
                message: res.data.msg
              })
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleClose () {
      this.$refs.formInline.resetFields()
      this.formInline = {},
        this.fileList = []
      this.disable = false
      this.dialogVisible = false
      this.handleClick()
    },
    getManageOrgList () {
      const param={orgType:2};
      getadminOrgInfoList(param).then(res => {
        if (res.data.code == 200) {
          this.manageOrgList = res.data.data
        }
      })
    },
    getCompanyInfo (id) {
      getAdminmanageOrgInfo(id).then(res => {
        if (res.data.code == '200') {
          this.formInline=res.data.data;
        }
      })
    },
  }
}

</script>
<style lang="less" scoped>
::v-deep .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.box-card {
  margin: 0 15px 15px 15px;
  .clearfix {
    font-weight: bold;
  }
  .box_left {
    width: 60%;
  }
  .right {
    width: 40%;
  }
  .btn {
    display: flex;
    justify-content: center;
  }
}
::v-deep .delUploadColor {
  .el-upload--picture-card {
    display: none;
  }
  i.el-icon-plus {
    display: none;
  }
}
</style>
